import { Get, Post } from '@/utils/request.ts'
import {
  reqDataBaseArticleBody,
  reqDataBaseTemplateBody,
  reqGetDataBaseCategoryBody,
  reqGetDataBaseRootCategoryBody,
  respDataBaseArticle,
  respDataBaseArticleDetail,
  respDataBaseCategoryData,
  respDataBaseRootCategoryData,
  respDataBaseTemplate,
} from '@/api/types/database'

export enum API {
  DATA_BASE_CATEGORY_URL = '/bioinfor/database/findDataBaseCategory',
  DATA_BASE_ROOT_CATEGORY_URL = '/bioinfor/database/findDataBaseRootCategory',

  DATA_BASE_ARTICLE_URL = '/bioinfor/database/findDataBaseArticles',
  DATA_BASE_ARTICLE_DETAIL_URL = '/bioinfor/database/findDataBaseArticleDetail',
  ADD_OR_UPDATE_DATABASE_ARTICLE_URL = '/bioinfor/database/addOrUpdateDataBaseArticle',
  DELETE_DATABASE_ARTICLE_URL = '/bioinfor/database/deleteDataBaseArticle',

  DATA_BASE_TEMPLATE_URL = '/bioinfor/database/findDataBaseTemplate',
  DATA_BASE_DELETE_TEMPLATE_URL = '/bioinfor/database/deleteDataBaseTemplate',
  ADD_OR_UPDATE_DATA_BASE_TEMPLATE_URL = '/bioinfor/database/addOrUpdateDataBaseTemplate',
  ADD_OR_UPDATE_DATA_BASE_CATEGORY_URL = '/bioinfor/database/addOrUpdateDataBaseCategory',

  DELETE_DATA_BASE_CATEGORY_URL = '/bioinfor/database/deleteDataBaseCategory',
}

// 查询数据库类型
export const reqGetDataBaseCategory = (
  reqData: Partial<reqGetDataBaseCategoryBody> = {},
) => Post<respDataBaseCategoryData[]>(API.DATA_BASE_CATEGORY_URL, reqData)

// 查询数据库分支
export const reqGetDataBaseRootCategory = (
  reqData: Partial<reqGetDataBaseRootCategoryBody> = {},
) =>
  Post<respDataBaseRootCategoryData[]>(API.DATA_BASE_ROOT_CATEGORY_URL, reqData)

// 查询数据库文章
export const reqGetDataBaseArticles = (
  reqData: Partial<reqDataBaseArticleBody> = {},
) => Post<respDataBaseArticle[]>(API.DATA_BASE_ARTICLE_URL, reqData)

// 查询文章详情
export const reqGetDataBaseArticleDetail = (id: number | string) =>
  Get<respDataBaseArticleDetail>(API.DATA_BASE_ARTICLE_DETAIL_URL + `/${id}`)

// 添加/修改文章
export const reqAddOrUpdateDataBaseArticle = (
  reqData: reqDataBaseArticleBody,
) => Post(API.ADD_OR_UPDATE_DATABASE_ARTICLE_URL, reqData)

// 删除文章
export const reqDeleteDataBaseArticle = (id: string) =>
  Get<string>(API.DELETE_DATABASE_ARTICLE_URL + '/' + id)

// 查询数据库模板
export const reqGetDataBaseTemplate = (
  reaData: Partial<reqDataBaseTemplateBody> = {},
) => Post<respDataBaseTemplate[]>(API.DATA_BASE_TEMPLATE_URL, reaData)

// 删除数据库模板
export const reqDeleteDataBaseTemplate = (id: string) =>
  Get<string>(API.DATA_BASE_DELETE_TEMPLATE_URL + '/' + id)

// 新增/修改数据库模板
export const reqAddOrUpdateDataBaseTemplate = (
  reqData: reqDataBaseTemplateBody,
) => Post<string>(API.ADD_OR_UPDATE_DATA_BASE_TEMPLATE_URL, reqData)

// 新增/修改数据库
export const reqAddOrUpdateDataBaseCategory = (
  reqData: reqGetDataBaseCategoryBody,
) => Post<number>(API.ADD_OR_UPDATE_DATA_BASE_CATEGORY_URL, reqData)

export const reqDeleteDataBaseCategory = (id: number) =>
  Get(API.DELETE_DATA_BASE_CATEGORY_URL + '/' + id)
